import $ from 'jquery'
var hostName = "http://localhost:8080/";//接口公共的ip或者域名
//path里定义了所有的接口
var path = {
    /*数据采集部分*/
    task: hostName + "opc/collect/allSampTasks",//获取目标OPC中所有采集任务
    createTask: hostName + "opc/collect/add/sampTask",//添加采集任务  最低10s
    createDottes: hostName + "opc/collect/addItemToTask",//向采集任务中 添加采集点
    runTask: hostName + "opc/collect/start/task/",//启动采集任务
    stopTask: hostName + "opc/collect/stop/task/",//停止采集任务
    singleTask: hostName + "opc/collect/getItems/by/",//获取 单个 采集任务的信息
    deleteTask: hostName + "opc/collect/delete/task/",//删除某个采集任务
    allDottes: hostName + "opc/collect/allItems",//获取当前OPCServer 下得所有采集点
    deleteDottes: hostName + "opc/collect/deleteItem",//删除采集任务中的采集点
    allLink: hostName + "opc/link/connects",//查询基本连接配置信息
    isLink: hostName + "opc/link/canConnect",//查看host是否可以连接
    linkStatus: hostName + "opc/link/isConnect",//查看OPCServer连接状态
    linkHost: hostName + "opc/link/try/connect",//连接HOST，获取所有OPCServer
    linkServer: hostName + "opc/link/connect/server",//连接opcserver，获取所有检测点
    allServers: hostName + "opc/link/servers",//获取当前host下所有servers
    createHost: hostName + "opc/link/createOrUpdate/connect",//获取当前host下所有servers
    currentLink: hostName + "opc/link/get/connectNow",//查看当前连接的host和opcServer
    deleteHostData: hostName + "opc/link/delete/connectInfo/",//查看当前连接的host和opcServer
    getOpcData: hostName + "opc/show/getData",// 获取采集数据
    getOtherDatas: hostName + "opc/show/getOtherDatas",// 获取其他数据
    updataOtherData: hostName + "opc/show/updataOtherData",// 修改或更新其他数据
    getOtherDataByKey: hostName + "opc/show/getOtherDataByKey",// 获取详细数据otherData
    
   };
var apiGet = function (url, data, success, error) {
    var option = {
        method: 'get',
        url: url,
        async: 'true',
        contentType: "application/x-www-form-urlencoded; charset=UTF-8",
        data: data,
        success: success,
        error: error
    };

    // console.log('测试',$.ajax(option).then())
    return $.ajax(option);
};
var apiPost = function (url, data, success, error) {
    if(url==path.createDottes || url == path.getOpcData){
        var option = {
            method: 'post',
            url: url,
            async: 'true',
            contentType: "application/json",
            data: data,
            dataType: 'json',
            success: success,
            error: error
        };
    }else{
        var option = {
            method: 'post',
            url: url,
            async: 'true',
            data: data,
            dataType: 'json',
            success: success,
            error: error
        };
    }

    return $.ajax(option);
};


var apiDelete = function (url, data, success, error) {
    var option = {
        method: 'DELETE',
        url: url,
        async: 'true',
        data: data,
        dataType: 'json',
        success: success,
        error: error
    };
    return $.ajax(option);
};
var jsonp = function (url, data, success, error) {
    var option = {
        method: 'post',
        url: url,
        async: 'false',
        data: data,
        dataType: "jsonp",
        success: success,
        error: error,
    };
    $.ajax(option);
};
var jsonp1 = function (url, data, success, error) {
    var option = {
        type: 'get',
        url: url,
        async: 'false',
        data: data,
        dataType: "jsonp",
        success: success,
        error: error,
    };
    $.ajax(option);
};
export {path,apiGet,apiPost,apiDelete}
